home *** CD-ROM | disk | FTP | other *** search
/ Aminet 31 / Aminet 31 (1999)(Schatztruhe)[!][Jun 1999].iso / Aminet / dev / gui / gtlayout.lha / Source / LTP_DrawBox.c < prev    next >
C/C++ Source or Header  |  1998-09-09  |  4KB  |  188 lines

  1. /*
  2. **    GadTools layout toolkit
  3. **
  4. **    Copyright © 1993-1998 by Olaf `Olsen' Barthel
  5. **        Freely distributable.
  6. **
  7. **    :ts=4
  8. */
  9.  
  10. #ifndef _GTLAYOUT_GLOBAL_H
  11. #include "gtlayout_global.h"
  12. #endif
  13.  
  14. #include "Assert.h"
  15.  
  16. VOID
  17. LTP_DrawMultiLineButton(struct RastPort *RPort,LONG Left,LONG Top,LONG Width,LONG Height,struct ImageInfo *ImageInfo,BOOL Bold)
  18. {
  19.     LONG Len,ThisTop,ThisLeft;
  20.     STRPTR *Lines = ImageInfo->Lines;
  21.     LONG LineCount = ImageInfo->LineCount;
  22.     STRPTR KeyStroke = ImageInfo->KeyStroke;
  23.     STRPTR Label;
  24.     ULONG OldStyle;
  25.     struct TextFont *OldFont;
  26.  
  27.     if(ImageInfo->Font)
  28.     {
  29.         OldFont = RPort->Font;
  30.  
  31.         SetFont(RPort,ImageInfo->Font);
  32.     }
  33.     else
  34.         OldFont = NULL;
  35.  
  36.     OldStyle = RPort->AlgoStyle;
  37.  
  38.     if(Bold)
  39.         SetSoftStyle(RPort,FSF_BOLD,FSF_BOLD);
  40.  
  41.     if(!LineCount)
  42.         LineCount = 1;
  43.  
  44.     ThisTop = Top + (Height - LineCount * RPort->TxHeight + 1) / 2;
  45.  
  46.     do
  47.     {
  48.         if(LineCount && Lines)
  49.             Label = *Lines++;
  50.         else
  51.             Label = ImageInfo->Label;
  52.  
  53.         Len = strlen(Label);
  54.  
  55.         ThisLeft = Left + (Width - TextLength(RPort,Label,Len)) / 2;
  56.  
  57.         LTP_PrintText(RPort,Label,Len,ThisLeft,ThisTop);
  58.  
  59.         if(KeyStroke)
  60.         {
  61.             if(KeyStroke >= Label && KeyStroke < Label + Len)
  62.             {
  63.                 if(KeyStroke != Label)
  64.                     ThisLeft += TextLength(RPort,Label,(ULONG)KeyStroke - (ULONG)(Label));
  65.  
  66.                 SetSoftStyle(RPort,FSF_UNDERLINED,FSF_UNDERLINED);
  67.  
  68.                 LTP_PrintText(RPort,KeyStroke,1,ThisLeft,ThisTop);
  69.  
  70.                 SetSoftStyle(RPort,0,FSF_UNDERLINED);
  71.  
  72.                 KeyStroke = NULL;
  73.             }
  74.         }
  75.  
  76.         ThisTop += RPort->TxHeight;
  77.     }
  78.     while(--LineCount > 0);
  79.  
  80.     if(Bold)
  81.         SetSoftStyle(RPort,OldStyle,FSF_BOLD);
  82.  
  83.     if(OldFont)
  84.         SetFont(RPort,OldFont);
  85. }
  86.  
  87. VOID
  88. LTP_DrawBox(struct RastPort *rp,struct DrawInfo *drawInfo,LONG left,LONG top,LONG width,LONG height,BOOL selected,BOOL ghosted,ImageInfo *imageInfo)
  89. {
  90.     LONG pen3,pen4;
  91.     LONG imageType;
  92.     LONG Width,Height;
  93.     UWORD *pens;
  94.  
  95.         // It doesn't work reliably under v2.04 without these
  96.  
  97.     if(!V39)
  98.         LTP_ResetRenderInfo(rp);
  99.  
  100.     pens = drawInfo->dri_Pens;
  101.  
  102.     if(selected)
  103.     {
  104.         pen3 = pens[FILLPEN];
  105.         pen4 = pens[FILLTEXTPEN];
  106.     }
  107.     else
  108.     {
  109.         pen3 = pens[BACKGROUNDPEN];
  110.         pen4 = pens[TEXTPEN];
  111.     }
  112.  
  113.     if(imageInfo->Emboss)
  114.     {
  115.         Width    = 3;
  116.         Height    = 2;
  117.     }
  118.     else
  119.     {
  120.         Width    = 2;
  121.         Height    = 1;
  122.     }
  123.  
  124.     if(!imageInfo->UseFrame)
  125.     {
  126.         LTP_RenderBevel(rp,pens,left,top,width,height,selected,imageInfo->Emboss ? 3 : 2);
  127.  
  128.         LTP_SetAPen(rp,pen3);
  129.  
  130.         LTP_FillBox(rp,left + Width,top + Height,width - 2 * Width,height - 2 * Height);
  131.     }
  132.     else
  133.     {
  134.         ULONG state;
  135.  
  136.         if(selected)
  137.             state = IDS_SELECTED;
  138.         else
  139.         {
  140.             if(ghosted)
  141.                 state = IDS_DISABLED;
  142.             else
  143.                 state = IDS_NORMAL;
  144.         }
  145.  
  146.         DrawImageState(rp,imageInfo->FrameImage,left,top,state,drawInfo);
  147.     }
  148.  
  149.     LTP_SetPens(rp,pen4,0,JAM1);
  150.  
  151.     switch(imageType = imageInfo->ImageType)
  152.     {
  153.         case IMAGECLASS_PICKER:
  154.  
  155.             LTP_DrawAdjustedPicker(rp,FALSE,left,top,width,height,drawInfo->dri_Resolution.X,drawInfo->dri_Resolution.Y);
  156.             break;
  157.  
  158.         case IMAGECLASS_MULTILINEBUTTON:
  159.  
  160.             LTP_DrawMultiLineButton(rp,left + Width,top + Height,width - 2 * Width,height - 2 * Height,imageInfo,imageInfo->Emboss);
  161.             break;
  162.  
  163.         case IMAGECLASS_LEFTINCREMENTER:
  164.         case IMAGECLASS_RIGHTINCREMENTER:
  165.  
  166.             LTP_DrawIncrementer(rp,drawInfo,imageType == IMAGECLASS_LEFTINCREMENTER,left + 2,top + 1,width - 4,height - 2);
  167.             break;
  168.  
  169.         #ifdef DO_TAPEDECK_KIND
  170.         {
  171.             case IMAGECLASS_BACKWARD:
  172.             case IMAGECLASS_FORWARD:
  173.             case IMAGECLASS_PREVIOUS:
  174.             case IMAGECLASS_NEXT:
  175.             case IMAGECLASS_RECORD:
  176.             case IMAGECLASS_PLAY:
  177.             case IMAGECLASS_STOP:
  178.             case IMAGECLASS_PAUSE:
  179.             case IMAGECLASS_EJECT:
  180.             case IMAGECLASS_REWIND:
  181.  
  182.                 LTP_DrawTapeButton(rp,imageInfo,left,top,width,height,drawInfo->dri_Resolution.X,drawInfo->dri_Resolution.Y,pen3);
  183.                 break;
  184.         }
  185.         #endif    /* DO_TAPEDECK_KIND */
  186.     }
  187. }
  188.